import {axios} from '../utils/request'
import {MODEL_MODULE, ML_MODULE} from "./_prefix";
import {MOCK} from "./_prefix";

/**
 * 新建模型 POST /model/add
 * @param {*} payload
 * @returns
 */
export const addModel = async payload => {
    const {configId, userId, modelName, machineLearningAlgorithm, trainParams} = payload;
    // const res = await axios.post(`${MOCK}/ml/models`, {
    const res = await axios.post(`${MODEL_MODULE}`, {
        configId,
        userId,
        modelName,
        machineLearningAlgorithm,
        trainParams
    })
    return res
}
/**
 * 新建DL模型 POST /model/add/dl
 * @param {*} payload
 * @returns
 */
export const addDLModel = async payload => {
    const {fileInfoId, configId, modelName, modelTypeId, argument} = payload;
    const res = await axios.post(`${MODEL_MODULE}/add/dl`, {
        fileInfoId,
        configId,
        modelName,
        modelTypeId,
        arguments: argument
    })
    return res//response
}
/**
 * 删除模型 GET /model/delete
 * @param modelId
 * @returns
 */
export const deleteModel=async modelId=>{
    const res=await axios.get(`${MODEL_MODULE}/delete`,{params:{modelId:modelId}})
    return res;
}
    /**
     * 获取全部模型 GET /model/get/all
     * @param userId
     * @returns
     */
    export const getAllModel = async payload => {
        const{ userId } = payload;
        const res = await axios.get(`${MODEL_MODULE}`, {
            params: {
                userId: userId
            }
        })
        // const res = await axios.get(`${MOCK}/ml/models:userId=1`)
        return res
    }
/**
 * 获取一个配置下的所有模型 GET
 * @param userId
 * @returns
 */
export const getModelByConfigId = async payload => {
    const{ configId,userId } = payload;
    const res = await axios.get(`${MODEL_MODULE}/configs/${configId}`, {params: {userId: userId}})
    // const res = await axios.get(`${MOCK}/ml/models/configs/:configId`)
    return res
}

/**
 * 获取一个模型 GET
 * @param userId
 * @returns
 */
export const getOneModel = async payload => {
    const{ modelId, userId } = payload;
    const res = await axios.get(`${MODEL_MODULE}/${modelId}?userId=${userId}`)
    // const res = await axios.get(`${MOCK}/ml/models/:modelId`)
    return res
}

    /**
     * 获取深度学习模型 GET /model/get/all/dl
     * @param userId
     * @returns
     */
    export const getAllDLModel = async userId => {
        const res = await axios.get(`${MODEL_MODULE}/get/all/dl`, {params: {userId: userId}})
        return res//response
    }
    /**
     * 获取dl模型详情 GET /model/get/detail/dl
     * @param modelId
     * @returns
     */
    export const getDLDetail = async modelId => {
        const res = await axios.get(`${MODEL_MODULE}/get/all/dl`, {params: {modelId: modelId}})
        return res//response
    }
    /**
     * change GET /model/change
     * @param modelId
     * @param modelName
     * @param modelTypeId
     * @returns
     */
    export const change=async data =>{
        const res=await axios.get(`${MODEL_MODULE}/change`,{params:data})
        return res;
    }
    /**
     * 获取某一类模型 GET /model/get/models
     * @param modelTypeId
     * @returns
     */
    export const getModels=async modelTypeId=>{
        const res=await axios.get(`${MODEL_MODULE}/get/models`,{params:{modelTypeId:modelTypeId}});
        return res;
    }
    /**
     * 训练 POST /model/train
     * @param modelId
     * @returns
     */
    export const train = async payload=>{
        const { modelId, userId } = payload;
        const res=await axios.post(`${MODEL_MODULE}/${modelId}/train?userId=1`,{
            params:{
                userId: userId
            }
        });
        // const res=await axios.get(`${MOCK}/ml/models/:modelId/train`);
        return res;
    }

    /**
     * 获取所有部署 GET
     * @param userId
     * @returns
     */
    export const getAllDeployment = async payload => {
        const{ userId } = payload;
        const res = await axios.get(`${ML_MODULE}/deployments?userId=${userId}`)
        return res
    }

    export const addDeployment = async payload => {
        const{ userId, modelId, deploymentName } = payload;
        const res = await axios.post(`${ML_MODULE}/deployments`,{
            userId, modelId, deploymentName
        })
        return res
    }





